home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / byacc 1.8.2 / mktemp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-04  |  1.1 KB  |  65 lines  |  [TEXT/R*ch]

  1. #ifndef THINK_C
  2. #include <exec/types.h>
  3. #include <exec/tasks.h>
  4. #include <dos/dos.h>
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #endif
  8.  
  9. char *mktemp(char *    template)
  10. {
  11.     char        letter = 'A';
  12.     BPTR        lock;
  13.     unsigned long    mytask;
  14.     char *        xptr;
  15.  
  16.  
  17.     if (template == (char *) NULL || *template == '\0')
  18.     return (char *) NULL;
  19.  
  20.     for (xptr = template; *xptr != '\0'; xptr++)
  21.     /* void */ ;
  22.     if (*--xptr != 'X')
  23.     return (char *) NULL;
  24.  
  25.     mytask = (unsigned long) FindTask((STRPTR) NULL);
  26.  
  27.     do {
  28.     *xptr = (mytask % 10) + '0';
  29.     mytask /= 10;
  30.     } while (xptr != template && *--xptr == 'X');
  31.  
  32.     if (*xptr == 'X') {
  33.     while (xptr != template && *xptr == 'X')
  34.         xptr--;
  35.     if (*xptr != 'X')
  36.         xptr++;
  37.     *xptr = letter;
  38.     }
  39.     else {
  40.     xptr++;
  41.     letter--;
  42.     }
  43.  
  44.     for (;;) {
  45.     lock = Lock(template, SHARED_LOCK);
  46.  
  47.     if (lock == (BPTR) NULL) {
  48.         if (IoErr() == ERROR_OBJECT_NOT_FOUND)
  49.         return template;
  50.     }
  51.     UnLock(lock);
  52.  
  53.     if (letter < 'Z')
  54.         letter++;
  55.     else {
  56.         if (*++xptr == '\0')
  57.         return (char *) NULL;
  58.         letter = 'A';
  59.     }
  60.     *xptr = letter;
  61.     }
  62.  
  63.     /*NOTREACHED*/
  64. }
  65.